package com.doudoukeji.service.Activity.myhospital;

import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.doudoukeji.service.Activity.disclaimer.DisclaimerActivity;
import com.doudoukeji.service.Activity.my.edituser.edituserinf.EditUserInfActivity;
import com.doudoukeji.service.Bean.HospitalLitapal;
import com.doudoukeji.service.Bean.ServiceLitapal;
import com.doudoukeji.service.Bean.Token;
import com.doudoukeji.service.R;
import com.doudoukeji.service.Utils.MyToast;
import com.doudoukeji.service.Utils.SharedPreferencesUtils;
import com.sanhai.android.mvp.EduActivity;

import org.apache.commons.lang3.StringUtils;

/**
 * @version 2.0
 * @类描述： 编辑医院和服务项目界面
 * @项目名称：ddgh
 * @类名称： MyActivity
 * @包名称： com.doudoukeji.service.Activity.my
 * @创建人：张强 boy
 * @创建时间：2016/3/9 14:12
 * @修改人：
 * @修改时间：2016/3/9 14:12
 * @修改备注： new parent class(用一句话描述修改了什么)
 */
public class EditMessageActivity extends EduActivity {
    //医院和服务项目的点击条目
    private RelativeLayout mRlEditMessageHospital, mRlEditMessageService;
    private Button mBtEditMessageOk;
    private TextView mTvEditMessageHospital, mTvEditMessageService;

    @Override
    public void setContentLayout() {
        setContentView(R.layout.activity_edit_message);
    }

    @Override
    public void init() {
        initView();
    }

    private void initView() {
        setText(R.id.tv_title, "编辑信息");
        mRlEditMessageHospital = (RelativeLayout) findViewById(R.id.rl_editmessage_hospital);
        mRlEditMessageService = (RelativeLayout) findViewById(R.id.rl_editmessage_service);
        mBtEditMessageOk = (Button) findViewById(R.id.bt_editmessage_ok);
        mTvEditMessageHospital = (TextView) findViewById(R.id.tv_editmessage_hospital);
        mTvEditMessageService = (TextView) findViewById(R.id.tv_editmessage_service);

        mRlEditMessageHospital.setOnClickListener(this);
        mRlEditMessageService.setOnClickListener(this);
        mBtEditMessageOk.setOnClickListener(this);

        //进入到编辑信息页面就讲标记设置为0，点击了确定后设置成1
        SharedPreferencesUtils.setParam(EditMessageActivity.this, "HosAndSer", "0");

    }

    @Override
    protected void onResume() {
        super.onResume();
        initData();
    }

    /**
     * 初始化界面数据
     */
    private void initData() {
        if (StringUtils.isNotBlank(Token.getServices())) {
            if (StringUtils.isNotBlank(ServiceLitapal.getServiceIdName(Token.getServices()))) {
                mTvEditMessageService.setText(ServiceLitapal.getServiceIdName(Token.getServices()).substring(0, ServiceLitapal.getServiceIdName(Token.getServices()).lastIndexOf(",")));
            }

        } else {
            mTvEditMessageService.setText("请选择服务项目");
        }

        if (StringUtils.isNotBlank(Token.getHospitals())) {
            if (StringUtils.isNotBlank(HospitalLitapal.getHospitalIdName(Token.getHospitals()))) {
                mTvEditMessageHospital.setText(HospitalLitapal.getHospitalIdName(Token.getHospitals()).substring(0, HospitalLitapal.getHospitalIdName(Token.getHospitals()).lastIndexOf(",")));
            }
        } else {
            mTvEditMessageHospital.setText("请选择服务医院");
        }
    }


    @Override
    public void onClickEvent(View view) {
        switch (view.getId()) {
            case R.id.rl_editmessage_hospital:
                IntentActivity(HospitalListActivity.class);
                break;

            case R.id.rl_editmessage_service:
                IntentActivity(EditUserInfActivity.class);
                break;

            case R.id.bt_editmessage_ok:

                if (StringUtils.isNotBlank(Token.getHospitals()) && StringUtils.isNotBlank(Token.getServices())) {
                    SharedPreferencesUtils.setParam(EditMessageActivity.this, "HosAndSer", "1");
                    IntentActivity(DisclaimerActivity.class);
                    this.finish();
                } else if (!StringUtils.isNotBlank(Token.getHospitals())) {
                    MyToast.DefaultmakeText(EditMessageActivity.this, "请选择服务医院", 1);
                } else if (!StringUtils.isNotBlank(Token.getServices())) {
                    MyToast.DefaultmakeText(EditMessageActivity.this, "请选择服务项目", 1);
                } else if (!StringUtils.isNotBlank(Token.getHospitals()) && !StringUtils.isNotBlank(Token.getServices())) {
                    MyToast.DefaultmakeText(EditMessageActivity.this, "请选择服务医院和服务项目", 1);
                }
                break;
        }
    }

    /**
     * 跳转界面
     *
     * @param Activityclass
     */
    private void IntentActivity(Class Activityclass) {
        Intent intent = new Intent(this, Activityclass);
        startActivity(intent);
    }

}
